class Employee::ContractsController < InheritedResources::Base
  respond_to :json
  load_resource

  def index
    respond_with EmployeeContractJsonSerializer.index_json @contracts
  end

  def create
    employee_contract = ::AddEmployeeContract.run permitted_params
    render CommandJsonSerializer.as_json employee_contract
  end

  def update
    employee_contract = ::UpdateEmployeeContract.run permitted_params
    render CommandJsonSerializer.as_json employee_contract
  end

  def update
    @contract.update permitted_params
    respond_with @contract
  end

  def list_valid_contracts
    respond_with EmployeeContractJsonSerializer.index_json ContractQuery.find_valid_certificates
  end

  def list_will_valid_contracts
    respond_with EmployeeContractJsonSerializer.index_json ContractQuery.find_will_valid_certificates
  end

  private
  def permitted_params
    params.permit(:employee_id, :valid_from, :valid_end, :contract_type_id, :number, :id)
  end
  
end